package com.example.xd.dialtest.socket;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.example.xd.dialtest.R;

public class SocketActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_socket);
        bindMyService();
//        doRegisterReceiver();
    }

    private void bindMyService() {
        Intent intent = new Intent(this, JWebSocketClientService.class);
        bindService(intent, mServiceConnection, BIND_AUTO_CREATE);
    }


    private ServiceConnection mServiceConnection = new ServiceConnection() {

        private JWebSocketClientService.JWebSocketClientBinder mBinder;

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            mBinder = (JWebSocketClientService.JWebSocketClientBinder) service;
            JWebSocketClientService service1 = mBinder.getService();
            service1.add();

        }

        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    };

    private void doRegisterReceiver() {
        ChatMessageReceiver chatMessageReceiver = new ChatMessageReceiver();
        IntentFilter intentFilter = new IntentFilter("com.example.xd.dialtest.socket");
        registerReceiver(chatMessageReceiver, intentFilter);


    }

    public class ChatMessageReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {

        }
    }
}
